package mw.live.table;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class GameTableModel extends AbstractTableModel {
	private static final long serialVersionUID = 7966734332882051791L;
	private String[] columnNames = { "Name", "Created by", "Creation time" };

	private List<GameInfo> data = new ArrayList<GameInfo>() {
		private static final long serialVersionUID = -3429707710780094004L;
		{
			add(new GameInfo("No games found.", "", ""));
		}
	};

	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return data.size();
	}

	public String getColumnName(int col) {
		return columnNames[col];
	}

	public Object getValueAt(int row, int col) {
		switch (col) {
			case 0:
				return data.get(row).name;
			case 1:
				return data.get(row).creator;
			case 2:
				return data.get(row).created;
		}
		return "";
	}

	public void addGame(GameInfo gameInfo) {
		synchronized(data) {
			data.add(gameInfo);
		}
	}
	
	public void addGame(String name, String creator, String created) {
		synchronized(data) {
			data.add(new GameInfo(name,creator,created));
		}
	}
	
	public void clear() {
		synchronized(data) {
			data.clear();
		}
	}

	@Override
	public boolean isCellEditable(int row, int col) {
		return false;
	}
}
